# ---- logging console ----
import logging;
# logging.basicConfig(level=logging.NOTSET);
#logging.basicConfig(level=logging.DEBUG,
 #                   format="%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s");

#logging.debug("lg");
#logging.info("aaa");
#logging.warning("bbb");
#logging.error("ccc");
#logging.critical("ddd");
# ---- logging file ----
import os.path;
import time;
# 设置变量
fileFormat = "PythonLog_" + time.strftime("%Y%m%d", time.localtime(time.time()));
logFormat = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s");
logLevel = logging.DEBUG;
logPath = "/log";
logLevel = logging.DEBUG;
# 创建logger
logger = logging.getLogger();
logger.setLevel(logLevel);
# 创建一个 stream handler，输出到控制台 --- 无需设置，logger会自动输出到控制台
# logConsoleHandler = logging.StreamHandler();
# logConsoleHandler.setLevel(logLevel);
# logConsoleHandler.setFormatter(logFormat);
# logger.addHandler(logConsoleHandler);
# 创建一个 file handler，输出到文件
logFile = os.path.abspath(logPath) + "/" + fileFormat + ".log";
logFileHandler = logging.FileHandler(logFile, mode = "w");
logFileHandler.setLevel(logLevel);
logFileHandler.setFormatter(logFormat);
logger.addHandler(logFileHandler);

